package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysQuestion;
import com.hl.sfzy.service.SysQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author ffc
 * @version 1.0
 * @description: TODO
 * @className: SysQuestionController
 * @date 2024/7/12 11:43
 */


@RestController
public class SysQuestionController {
    @Autowired
    SysQuestionService sysQuestionService;

    //新增问题
    @PostMapping("/sysQuestion")
    public Result add(@RequestBody SysQuestion sysQuestion){
        return sysQuestionService.add(sysQuestion) > 0 ? Result.success() : Result.error();
    }

    //根据id删除问题
    @DeleteMapping("/sysQuestion/{id}")
    public Result remove(@PathVariable("id") Integer id){
        return sysQuestionService.remove(id) > 0 ? Result.success() : Result.error();
    }

    //根据id批量删除
    @DeleteMapping("/sysQuestion")
    public Result removeBatch(Integer[] ids){
        return sysQuestionService.removeBatch(ids) > 0 ? Result.success() : Result.error();
    }

    //根据条件查找所有
    @GetMapping("/sysQuestion")
    public Result find(SysQuestion sysQuestion){
        List<SysQuestion> list = sysQuestionService.find(sysQuestion);
        return  Result.success(list);
    }

    //根据id查找
    @GetMapping("/sysQuestion/{id}")
    public Result findById(@PathVariable("id") Integer id){
        SysQuestion sysQuestion = sysQuestionService.findById(id);
        return Result.success(sysQuestion);
    }

    //根据条件分页查询
    @GetMapping("/sysQuestion/page")
    public Result findPage(@RequestParam(value = CommonConstant.PAGE_NUM,required = true,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum ,
                           @RequestParam(value = CommonConstant.PAGE_SIZE,required = true,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize ,
                           SysQuestion sysQuestion){
        Map<String, Object> map = sysQuestionService.findPage(pageNum, pageSize, sysQuestion);
        return Result.success(map);
    }

    //根据条件排序分页查询
    @GetMapping("/sysQuestion/order")
    public Result findOrder(@RequestParam(value = CommonConstant.PAGE_NUM,required = true,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum ,
                           @RequestParam(value = CommonConstant.PAGE_SIZE,required = true,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize ,
                            Integer order
                           ){
        Map<String, Object> map = sysQuestionService.findOrder(pageNum, pageSize, order);
        return Result.success(map);
    }


}
